package models

import (
	"gorm.io/gorm"
	"hospital-srv/basic/inits"
	"time"
)

// 设备表
type Equipment struct {
	Id             uint64         `gorm:"column:id;type:bigint UNSIGNED;comment:设备id;primaryKey;not null;" json:"id"`                               // 设备id
	BrandId        uint64         `gorm:"column:brand_id;type:bigint UNSIGNED;comment:品牌id;not null;" json:"brand_id"`                              // 品牌id
	EquipmentName  string         `gorm:"column:equipment_name;type:varchar(255);comment:设备名称;not null;" json:"equipment_name"`                     // 设备名称
	EquipmentModel string         `gorm:"column:equipment_model;type:varchar(255);comment:设备型号;not null;" json:"equipment_model"`                   // 设备型号
	Manufacturer   string         `gorm:"column:manufacturer;type:varchar(255);comment:生产厂商;not null;" json:"manufacturer"`                         // 生产厂商
	CreatedAt      time.Time      `gorm:"column:created_at;type:datetime(3);comment:创建时间;not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"` // 创建时间
	UpdatedAt      time.Time      `gorm:"column:updated_at;type:datetime(3);comment:修改时间;not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"` // 修改时间
	DeletedAt      gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);comment:删除时间;default:NULL;" json:"deleted_at"`                          // 删除时间
}

// 设备表
func (e *Equipment) TableName() string {
	return "equipment"
}

// 设备添加
func (e *Equipment) EquipmentAdd() error {
	return inits.DB.Create(&e).Error
}

// 设备删除
func (e *Equipment) EquipmentDel() error {
	return inits.DB.Where("id = ?", e.Id).Delete(&e).Error
}

// 设备修改
func (e *Equipment) EquipmentUpdate() error {
	return inits.DB.Where("id = ?", e.Id).Updates(&e).Error
}

// 设备查询
func (e *Equipment) EquipmentFind() (EquipmentFind []*Equipment, err error) {
	err = inits.DB.Find(&EquipmentFind).Error
	return
}

// 设备详情
func (e *Equipment) EquipmentDetails() error {
	return inits.DB.Where("id = ?", e.Id).Limit(1).Find(&e).Error
}

// 设备id查询
func (e *Equipment) EquipmentId() error {
	return inits.DB.Model(&e).Where("id = ?", e.Id).Limit(1).Find(&e).Error
}
